/*
 * SystemException.h
 *
 *  Created on: May 8, 2013
 *      Author: Lucifer
 */

#ifndef SYSTEMEXCEPTION_H_
#define SYSTEMEXCEPTION_H_

namespace BFX
{

/**
 * Throws an exception for a system error code.
 */
class SystemException: public Exception
{
public:
	/**
	 * Creates a new instance with last system error that occurred.
	 */
	SystemException();
	/**
	 * Creates a new instance with last system error that occurred.
	 * @param[in] nErrorCode The error code associated with this exception.
	 */
	SystemException(int nErrorCode);
	/**
	 * Creates a new instance with last system error that occurred.
	 * @param[in] pszMessage A detailed description of the error.
	 */
	SystemException(const char* pszMessage);
	/**
	 * Creates a new instance with the specified error.
	 * @param[in] nErrorCode The error code associated with this exception.
	 * @param[in] pszMessage A detailed description of the error.
	 */
	SystemException(int nErrorCode, const char* pszMessage);
	/**
	 * Copy constructor.
	 * @param[in] src The source object copy from.
	 */
	SystemException(const SystemException& src);
	/**
	 * Destroys the instance.
	 */
	virtual ~SystemException() throw();

	/**
	 * Gets the error code.
	 * @return The platform dependent error code.
	 */
	int GetErrorCode() const;

	/**
	 * The static helper to retrieves the calling thread's last system error code value.
	 * @return The calling thread's last system error code.
	 */
	static int GetLastError();
	/**
	 * The static helper to translate error code to string.
	 * @param[in] nErrorCode
	 * @return
	 */
	static String GetErrorMessage(int nErrorCode);

	/**
	 * Gets a message that describes the current exception.
	 * @return
	 */
	virtual const char* GetMessage() const;
	/**
	 * The category name of this exception.
	 * @return
	 */
	virtual const char* GetExceptionName() const
	{
		return "SystemException";
	}

private:
	int m_nErrorCode;
	mutable String m_strErrorMsg;
};

#define	BFX_THROW_SYSEXCEPTION()			throw BFX::SystemException()
#define	BFX_THROW_SYSEXCEPTION1(codeOrMsg)	throw BFX::SystemException(codeOrMsg)
#define	BFX_THROW_SYSEXCEPTION2(code, msg)	throw BFX::SystemException(code, msg)

} /* namespace BFX */

#endif /* SYSTEMEXCEPTION_H_ */
